<template>
  <el-row>
    <el-col :span="6">
      <div style="padding: 20px;height: 500px;overflow-y: auto;">
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="危险源列表">
            <el-select v-model="form.region" placeholder="请选择危险源" @change="handleChange">
              <el-option label="罐区" value="storage" />
              <el-option label="库区" value="reservoir" />
              <el-option label="生产场所" value="production" />
            </el-select>
          </el-form-item>
        </el-form>
        <el-table
          :data="tableData"
          border
          style="width: 100%"
          @row-click="handleTable"
        >
          <el-table-column
            prop="label"
            label="危险源名称"
          />
          <el-table-column
            prop="name"
            label="类型"
          />
          <el-table-column
            prop="number"
            label="设备数量"
          />
        </el-table>
      </div>
    </el-col>
    <el-col :span="18">
      <p>
        {{ label }}
      </p>
    </el-col>
  </el-row>
</template>

<script>
import { getProduction } from '@/api/mhm/productionSiteManage'
import { getReservoir } from '@/api/mhm/reservoirAreaManage'
import { getStorage } from '@/api/mhm/storageAreaManage'
export default {
  name: 'HazardDetectionCenter',
  data() {
    return {
      form: {},
      tableData: [],
      label: null
    }
  },
  created() {
  },
  methods: {
    handleChange(data) {
      switch (data) {
        case 'storage':
          getStorage().then(res => {
            this.tableData = res.content.map(element => {
              element.label = element.storageAreaName
              return element
            })
          })
          break
        case 'reservoir':
          getReservoir().then(res => {
            this.tableData = res.content.map(element => {
              element.label = element.reservoirAreaName
              return element
            })
          })
          break
        case 'production':
          getProduction().then(res => {
            this.tableData = res.content.map(element => {
              element.label = element.unitName
              return element
            })
          })
          break
      }
    },
    handleTable(data) {
      console.log(data)
      this.label = data.label
    }
  }
}
</script>

<style scoped>

</style>
